package com.gcxy.controller;


import com.gcxy.dto.Account.*;
import com.gcxy.service.AccountInfoService;
import com.gcxy.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wlp
 * @since 2023-12-20
 */
@RestController
@RequestMapping("/accountInfo")
@Api(tags = "人员管理")
public class AccountInfoController {
    private Logger logger= LoggerFactory.getLogger(getClass());
    @Autowired
    private AccountInfoService accountInfoService;
    @ApiOperation(value = "用户登录")
    @PostMapping("/login")
    public R login(@Valid @RequestBody LoginDto requestBody) {
        logger.info("正在登录");
        R result=accountInfoService.login(requestBody);
        return result;
    }
    @ApiOperation(value = "用户注册")
    @PostMapping("register")
    public R register(@Valid @RequestBody RegisterDto requestBody){
        logger.info("正在进行注册");
        R result=accountInfoService.register(requestBody);
        return result;
    }
    @ApiOperation("获取用户")
    @GetMapping("current")
    public R current(@RequestHeader String token){
        logger.info("正在获取用户");
        R result=accountInfoService.current(token);
        return result;
    }
    @ApiOperation("新增用户")
    @PostMapping("insert")
    public R addUser(@Valid @RequestBody InsertDto requestBody){
        logger.info("正在新增人员");
        R result=accountInfoService.addAccount(requestBody);
        return result;
    }

    @ApiOperation("分页查询")
    @PostMapping("page")
    public R pageAccount(@RequestBody AccountPageDto requestBody){
        logger.info("正在人员分页");
        R result =accountInfoService.pageAccount(requestBody);
        return result;
    }

    @ApiOperation("修改")
    @PutMapping("update")
    public R updateAccount(@Valid @RequestBody UpdateDto requestBody){
        logger.info("正在修改人员");
        R result=accountInfoService.updateAccount(requestBody);
        return result;
    }
    @ApiOperation("修改人员状态")
    @PutMapping("updateState/{account}/{accState}")
    public R updateState(@PathVariable String account,@PathVariable Integer accState){
        logger.info("正在修改人员状态");
        R result=accountInfoService.updateState(account,accState);
        return result;
    }

}

